package com.zxr.common.utils;

import java.util.HashMap;
import java.util.Map;

public class ExpireDataUtil {

    private static Map<String,ExpireData> map = new HashMap();
    //添加一个键值对
    public static void add(String key,String value,long expireSeconds){
        ExpireData expireData = new ExpireData(key,value,expireSeconds);
        map.put(key,expireData);
    }
    //根据key获取value
    public static String get(String key){
        ExpireData expireData = map.get(key);
        if(expireData == null){
            return null;
        }
        long nowTime = System.currentTimeMillis() / 1000;
        if(nowTime < expireData.getEndTime()){
            return expireData.getValue();
        }else{
            return null;
        }
    }


}